package com.cnpinxi.service;

import com.cnpinxi.domain.Product;
import com.cnpinxi.domain.ResourceRelation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2017-3-29.
 */
@Service("productService")
public class ProductServiceImpl extends com.cnpinxi.service.ProductBase implements ProductService {

    @Autowired
    ResourceRelationService resourceRelationService;


    @Override
    public void modifyProduct(Product product) {
        Long productId = product.getProductId();
        if (productId == null) {
            super.insertProduct(product);
        } else {
            super.updateProduct(product);
        }
    }

    @Override
    public Product getProduct(Map<String, String> map) {
        return productMapper.getProduct(map);
    }



    @Override
    public List<Product> getProductList(Map<String, String> map) {
        List<Product> productList=  productMapper.getProductList(map);
        for(Product product :productList){
            map.put("resourceRelationType",String.valueOf(ResourceRelation.RESOURCE_RELATION_TYPE_PRODUCT));
            map.put("resourceRelationId",String.valueOf(product.getProductId()));
            List<ResourceRelation> resourceRelationList=   resourceRelationService.getResourceRelationList(map);
            product.setResourceRelationList(resourceRelationList);
        }

        return productList;
    }




}
